/**
 * Created by Will Bean on 2016/4/27.
 */
import React, { Component, PropTypes} from 'react'

class FileInput extends Component {
    constructor() {
        super();
        this.state = {
            files: []
        }
    }

    handleChange(e) {
        var files = [];
        for (var i = 0; i < e.target.files.length; i++) {
            var file = e.target.files.item(i);
            if (!(/^image\/.*$/i.test(file.type))) {
                continue;            //不是图片 就跳出这一次循环
            }
            files.push(file);console.log(files)
        }
        this.setState({
            files: files
        });
        this.props.onChange(files);
    }

    render() {
        const { accept, fileClass,noMultiple } = this.props;
        return (
            <input disabled={this.props.disabled} type="file" accept={accept} className={fileClass} onChange={this.handleChange.bind(this)} multiple={noMultiple?false:true} />
        )
    }
}

FileInput.propTypes = {
    onChange: PropTypes.func.isRequired,
    accept: PropTypes.string,
    fileClass: PropTypes.string
};

export default FileInput